package com.neuralnoise.hibernate.facebook;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.MappedSuperclass;

@MappedSuperclass
public abstract class AbstractUser implements java.io.Serializable {

	private static final long serialVersionUID = 6574836489824717881L;

	private String id;
	
	private Set<UserTypeRelationship> userTypeRelationships = new HashSet<UserTypeRelationship>(0);
	
	private Set<User> usersForSubject = new HashSet<User>(0);
	private Set<User> usersForObject = new HashSet<User>(0);
	
	public AbstractUser() { }
	
	public AbstractUser(String id) {
		this.id = id;
	}
	
	public AbstractUser(String id, Set<UserTypeRelationship> userTypeRelationships,
			Set<User> usersForSubject, Set<User> usersForObject) {
		this(id);
		this.userTypeRelationships = userTypeRelationships;
		this.usersForSubject = usersForSubject;
		this.usersForObject = usersForObject;
	}

	@Id
	@Column(name = "id", unique = true, nullable = false, length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinTable(name = "UserTypeRelationship", joinColumns=@JoinColumn(name="user"))
	public Set<UserTypeRelationship> getUserTypeRelationships() {
		return this.userTypeRelationships;
	}

	public void setUserTypeRelationships(Set<UserTypeRelationship> userTypeRelationships) {
		this.userTypeRelationships = userTypeRelationships;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "usersForObject")
	public Set<User> getUsersForSubject() {
		return this.usersForSubject;
	}

	public void setUsersForSubject(Set<User> usersForSubject) {
		this.usersForSubject = usersForSubject;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "FacebookFriendOf", joinColumns = { @JoinColumn(name = "subject", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "object", nullable = false, updatable = false) })
	public Set<User> getUsersForObject() {
		return this.usersForObject;
	}

	public void setUsersForObject(Set<User> usersForObject) {
		this.usersForObject = usersForObject;
	}

}
